package com.shujia.scala

import scala.io.Source

object Demo30implicit {
  def main(args: Array[String]): Unit = {

    /**
      * 隐式转换类
      *
      */

    val fileRead = new FileRead("data/students.txt")
    val student: List[String] = fileRead.read()

    println(student)

    /**
      * String 类型被隐式转换成了FIleRead 类型，所以String 有了Read方法
      *
      */
    val path = "data/students.txt"
    val list: List[String] = path.read()


    val words: List[String] = "data/words.txt".read()


  }


  /**
    * 隐式转换类可以隐式的将类的构造函数类型转换成当前类的类型
    *
    * String  -- 隐式转换-->   FileRead
    */
  implicit class FileRead(path: String) {
    def read(): List[String] = {
      Source.fromFile(path).getLines().toList
    }
  }


}

